﻿@model Inscriptionem.Areas.Inscriptionem.Models.Views.CommentCollectionViewModel

@{
    ViewBag.Title = "Inscriptionem » Comments";
    Layout = "../Shared/Layout.cshtml";

    ViewBag.CurrentPage = "Comments";
    
    int currentPage = Model.Page + 1;
    int totalPages = (Model.Comments.Count() / 25) + 1;
}

<div class="outer" id="contentwrap">
    @{Html.RenderPartial("NavigationMenu");}
    <div class="postcont">
		<div id="content">
            <div class="post type-post status-publish format-standard hentry">
                <h2 class="title">Comments</h2>
                <div style="float: right; margin-top: -25px;">
                    <form action="/Inscriptionem/Comment/Search" method="post">
                        <input type="text" name="Text" />
                        <input type="hidden" name="Page" value="0" />
                        <input type="submit" value="Search" />
                    </form>
                </div>
                <div class="postdate-single error-message"></div>

                <table width="100%">
                    <thead>
                        <tr class="postdate">
                            <td>First Name</td>
                            <td>Nick Name</td>
                            <td>Last Name</td>
                            <td>Mail</td>
                            <td>Language</td>
                            <td>Section</td>
                            <td>Title</td>
                            <td>Comment</td>
                            <td style="width: 60px;"></td>
                            <td style="width: 60px;"></td>
                            <td style="width: 60px;"></td>
                        </tr>
                    </thead>
                    <tbody>
                    @foreach (var comment in Model.Comments.Skip(25 * Model.Page).Take(25))
                    {
                        string title = comment.Post == null ? comment.Page.Title : comment.Post.Title;
                        
                        var categories = comment.Post == null ? (IEnumerable<Inscriptionem.ORM.Category>)null : comment.Post.PostCategories.Select(pc => pc.Category);
                        var section = comment.Post == null ? comment.Page.Section : categories.First().Section;
                            
                        var language = section.Language;
                    <text>
                    <tr>
                        <td>@comment.Member.FirstName</td>
                        <td>@comment.Member.NickName</td>
                        <td>@comment.Member.LastName</td>
                        <td>@comment.Member.Mail</td>
                        <td>@language.LocalizedName</td>
                        <td>@(section.LocalizedName)</td>
                        <td>@(title.Length >= 25 ? title.Substring(0, 25) : title)</td>
                        <td>@(comment.Content.Length >= 25 ? comment.Content.Substring(0, 25) : comment.Content)</td>
                        <td>
                            <form method="post" action="/Inscriptionem/Comment/Edit">
                                <input type="hidden" name="ID" value="@comment.ID" />
                                <input type="submit" value="Edit" />
                            </form>
                        </td>
                        <td>
                            <form method="post" action="/Inscriptionem/Comment/Approve">
                                <input type="hidden" name="Page" value="@Model.Page" />
                                <input type="hidden" name="ID" value="@comment.ID" />
                                <input type="submit" value="Approve" />
                            </form>
                        </td>
                        <td>
                            <form method="post" action="/Inscriptionem/Comment/Decline">
                                <input type="hidden" name="Page" value="@Model.Page" />
                                <input type="hidden" name="ID" value="@comment.ID" />
                                <input type="submit" value="Decline" />
                            </form>
                        </td>
                    </tr>
                    </text>
                    }
                    </tbody>
                </table>
			</div>
            <div class="navigation">
            @{Html.RenderAction("Pagination",
                    new Inscriptionem.Models.Menu.Requests.PaginationRequestModel() {
                        Language = "English",
                        Section = "",
                        CurrentPage = currentPage,
                        TotalPages = totalPages,
                        MaximumLinkCount = 7,
                        UrlTemplate = "/Inscriptionem/Comment/Page/{ID}"
                        });
            }
			</div>
        </div>
	</div>	
</div>
